{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# $H_{div}$ 和 $H_{curl}$ 空间"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 1. 基础知识"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "###  1. 1 二维情形"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "给定反对称矩阵：\n",
    "$$\n",
    "W = \\begin{pmatrix}\n",
    "0 & 1\\\\ -1 & 0 \n",
    "\\end{pmatrix}\n",
    "$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$\n",
    "\\nabla q = (\\frac{\\partial q}{\\partial x}, \\frac{\\partial q}{\\partial y})\n",
    "$$\n",
    "\n",
    "$$\n",
    "\\mathbf{rot}\\, q = (\\frac{\\partial q}{\\partial y}, - \\frac{\\partial q}{\\partial x}) = \\nabla  q W^T\n",
    "$$\n",
    "\n",
    "$$\n",
    "\\mathrm{rot}\\, \\mathbf v = \\frac{\\partial v_2}{\\partial x} - \\frac{\\partial v_1}{\\partial y}\n",
    "$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "给定三角形单元 $\\tau = (\\mathbf x_0, \\mathbf x_1, \\mathbf x_2)$, 其三个顶点按逆时针方向排序， 对应重心坐标函数分别为 $\\lambda_0$, $\\lambda_1$, $\\lambda_2$， 其梯度为："
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$\n",
    "\\begin{aligned}\n",
    "\\nabla\\lambda_0 = \\frac{1}{2|\\tau|}(\\mathbf x_2 - \\mathbf x_1)W\\\\\n",
    "\\nabla\\lambda_1 = \\frac{1}{2|\\tau|}(\\mathbf x_0 - \\mathbf x_2)W\\\\\n",
    "\\nabla\\lambda_2 = \\frac{1}{2|\\tau|}(\\mathbf x_1 - \\mathbf x_0)W\\\\\n",
    "\\end{aligned}\n",
    "$$\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$\n",
    "\\begin{aligned}\n",
    "\\mathbf{rot}\\, \\lambda_0 =\\nabla\\lambda_0 W^T = \\frac{1}{2|\\tau|}(\\mathbf x_2 - \\mathbf x_1)\\\\\n",
    "\\mathbf{rot}\\, \\lambda_1 =\\nabla\\lambda_1 W^T= \\frac{1}{2|\\tau|}(\\mathbf x_0 - \\mathbf x_2)\\\\\n",
    "\\mathbf{rot}\\, \\lambda_2 =\\nabla\\lambda_2 W^T = \\frac{1}{2|\\tau|}(\\mathbf x_1 - \\mathbf x_0)\\\\\n",
    "\\end{aligned}\n",
    "$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$\n",
    "\\mathbf \\phi_{i, j}^{(1)} = \\lambda_i \\mathbf{rot}\\,\\lambda_j,\\quad\n",
    "\\mathbf \\phi_{i, j}^{(2)} = \\lambda_i \\nabla \\lambda_j\n",
    "$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 1. 2 三维情形"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "给定三维空间中的标量函数 $q$ 和向量函数 $\\mathbf v = (v_1, v_2, v_3)$, 常用的算子有\n",
    "\n",
    "\n",
    "$$\n",
    "\\nabla q = (\\frac{\\partial q}{\\partial x}, \\frac{\\partial q}{\\partial y}, \\frac{\\partial q}{\\partial z})\n",
    "$$\n",
    "\n",
    "$$\n",
    "\\nabla\\times \\mathbf v = (\\frac{\\partial v_3}{\\partial y} - \\frac{\\partial v_2}{\\partial z}, \\frac{\\partial v_1}{\\partial z} - \\frac{\\partial v_3}{\\partial x}, \\frac{\\partial v_2}{\\partial x} - \\frac{\\partial v_1}{\\partial y})\n",
    "$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "给定四面体单元 $\\tau = (\\mathbf x_0, \\mathbf x_1, \\mathbf x_2， \\mathbf x_3)$, 其四个顶点排列满足右手法则，其四个面分别为：\n",
    "\n",
    "$$\n",
    "f_0 := (\\mathbf x_1, \\mathbf x_2, \\mathbf x_3)\\\\\n",
    "f_1 := (\\mathbf x_0, \\mathbf x_3, \\mathbf x_2)\\\\\n",
    "f_2 := (\\mathbf x_0, \\mathbf x_1, \\mathbf x_3)\\\\\n",
    "f_3 := (\\mathbf x_0, \\mathbf x_2, \\mathbf x_1)\\\\\n",
    "$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "六条边为：\n",
    "\n",
    "$$\n",
    "e_0 : = (\\mathbf x_0, \\mathbf x_1)\\\\\n",
    "e_1 : = (\\mathbf x_0, \\mathbf x_2)\\\\\n",
    "e_2 : = (\\mathbf x_0, \\mathbf x_3)\\\\\n",
    "e_3 : = (\\mathbf x_1, \\mathbf x_2)\\\\\n",
    "e_4 : = (\\mathbf x_1, \\mathbf x_3)\\\\\n",
    "e_5 : = (\\mathbf x_2, \\mathbf x_3)\\\\\n",
    "$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "对应重心坐标函数分别为 $\\lambda_0$, $\\lambda_1$, $\\lambda_2$ 和 $\\lambda_3$, 其对应梯度为：\n",
    "\n",
    "$$\n",
    "\\nabla \\lambda_0 = \\frac{1}{6|\\tau|}(\\mathbf x_3 - \\mathbf x_1)\\times(\\mathbf x_2 - \\mathbf x_1)\\\\\n",
    "\\nabla \\lambda_1 = \\frac{1}{6|\\tau|}(\\mathbf x_2 - \\mathbf x_0)\\times(\\mathbf x_3 - \\mathbf x_0)\\\\\n",
    "\\nabla \\lambda_2 = \\frac{1}{6|\\tau|}(\\mathbf x_3 - \\mathbf x_0)\\times(\\mathbf x_1 - \\mathbf x_0)\\\\\n",
    "\\nabla \\lambda_3 = \\frac{1}{6|\\tau|}(\\mathbf x_1 - \\mathbf x_0)\\times(\\mathbf x_2 - \\mathbf x_0)\\\\\n",
    "$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 2. $RT$ 元"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 2.1 三角形"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* $RT_0$ "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "基函数为:\n",
    "\n",
    "$$\n",
    "\\mathbf \\phi_0 = \\lambda_1 \\mathbf{rot}\\,\\lambda_2 - \\lambda_2 \\mathbf{rot}\\,\\lambda_1\\\\\n",
    "\\mathbf \\phi_1 = \\lambda_2 \\mathbf{rot}\\,\\lambda_0 - \\lambda_0 \\mathbf{rot}\\,\\lambda_2\\\\\n",
    "\\mathbf \\phi_2 = \\lambda_0 \\mathbf{rot}\\,\\lambda_1 - \\lambda_1 \\mathbf{rot}\\,\\lambda_0\n",
    "$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "对偶基为：\n",
    "\n",
    "$$\n",
    "\\Phi_0(\\mathbf u) = \\int_{e_0}\\mathbf u\\cdot \\mathbf n_0 \\mathrm d s\\\\\n",
    "\\Phi_1(\\mathbf u) = \\int_{e_1}\\mathbf u\\cdot \\mathbf n_1 \\mathrm d s\\\\\n",
    "\\Phi_2(\\mathbf u) = \\int_{e_2}\\mathbf u\\cdot \\mathbf n_2 \\mathrm d s\\\\\n",
    "$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* $BDM_1$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "在 $RT_0$ 的基础上增加基函数：\n",
    "\n",
    "$$\n",
    "\\mathbf \\psi_0 = \\lambda_1 \\mathbf{rot}\\,\\lambda_2 + \\lambda_2 \\mathbf{rot}\\,\\lambda_1\\\\\n",
    "\\mathbf \\psi_1 = \\lambda_2 \\mathbf{rot}\\,\\lambda_0 + \\lambda_0 \\mathbf{rot}\\,\\lambda_2\\\\\n",
    "\\mathbf \\psi_2 = \\lambda_0 \\mathbf{rot}\\,\\lambda_1 + \\lambda_1 \\mathbf{rot}\\,\\lambda_0\n",
    "$$\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "对偶基为：\n",
    "\n",
    "$$\n",
    "\\begin{align}\n",
    "\\Psi_0(\\mathbf u) =& 3\\int_{e_0}\\mathbf u\\cdot \\mathbf n_0(\\lambda_1 - \\lambda_2) \\mathrm d s\\\\\n",
    "\\Psi_1(\\mathbf u) =& 3\\int_{e_1}\\mathbf u\\cdot \\mathbf n_1(\\lambda_2 - \\lambda_0) \\mathrm d s\\\\\n",
    "\\Psi_2(\\mathbf u) =& 3\\int_{e_2}\\mathbf u\\cdot \\mathbf n_2(\\lambda_0 - \\lambda_1) \\mathrm d s\\\\\n",
    "\\end{align}\n",
    "$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* $RT_1$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$\n",
    "\\mathbf \\phi_0 = \\lambda_1(\\lambda_1 \\mathbf{rot}\\,\\lambda_2 - \\lambda_2 \\mathbf{rot}\\,\\lambda_1)\\\\\n",
    "\\mathbf \\phi_1 = \\lambda_2(\\lambda_1 \\mathbf{rot}\\,\\lambda_2 - \\lambda_2 \\mathbf{rot}\\,\\lambda_1)\\\\\n",
    "\\mathbf \\phi_2 = \\lambda_2(\\lambda_2 \\mathbf{rot}\\,\\lambda_0 - \\lambda_0 \\mathbf{rot}\\,\\lambda_2)\\\\\n",
    "\\mathbf \\phi_3 = \\lambda_0(\\lambda_2 \\mathbf{rot}\\,\\lambda_0 - \\lambda_0 \\mathbf{rot}\\,\\lambda_2)\\\\\n",
    "\\mathbf \\phi_4 = \\lambda_0(\\lambda_0 \\mathbf{rot}\\,\\lambda_1 - \\lambda_1 \\mathbf{rot}\\,\\lambda_0)\\\\\n",
    "\\mathbf \\phi_5 = \\lambda_1(\\lambda_0 \\mathbf{rot}\\,\\lambda_1 - \\lambda_1 \\mathbf{rot}\\,\\lambda_0)\\\\\n",
    "\\mathbf \\phi_6 = \\lambda_0(\\lambda_1 \\mathbf{rot}\\,\\lambda_2 - \\lambda_2 \\mathbf{rot}\\,\\lambda_1)\\\\\n",
    "\\mathbf \\phi_7 = \\lambda_1(\\lambda_2 \\mathbf{rot}\\,\\lambda_0 - \\lambda_0 \\mathbf{rot}\\,\\lambda_2)\\\\\n",
    "\\mathbf \\phi_8 = \\lambda_2(\\lambda_0 \\mathbf{rot}\\,\\lambda_1 - \\lambda_1 \\mathbf{rot}\\,\\lambda_0)\\\\\n",
    "$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 2.2 四面体单元"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* $RT_0$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "基函数为：\n",
    "\n",
    "$$\n",
    "\\begin{align}\n",
    "\\mathbf \\phi_0 = 2(\\lambda_1\\nabla\\lambda_2\\times\\nabla\\lambda_3 + \\lambda_2\\nabla\\lambda_3\\times\\nabla\\lambda_1 + \\lambda_3\\nabla\\lambda_1\\times\\nabla\\lambda_2)\\\\\n",
    "\\mathbf \\phi_1 = 2(\\lambda_0\\nabla\\lambda_3\\times\\nabla\\lambda_2 + \\lambda_3\\nabla\\lambda_2\\times\\nabla\\lambda_0 + \\lambda_2\\nabla\\lambda_0\\times\\nabla\\lambda_3)\\\\\n",
    "\\mathbf \\phi_2 = 2(\\lambda_0\\nabla\\lambda_1\\times\\nabla\\lambda_3 + \\lambda_1\\nabla\\lambda_3\\times\\nabla\\lambda_0 + \\lambda_3\\nabla\\lambda_0\\times\\nabla\\lambda_1)\\\\\n",
    "\\mathbf \\phi_3 = 2(\\lambda_0\\nabla\\lambda_2\\times\\nabla\\lambda_1 + \\lambda_2\\nabla\\lambda_1\\times\\nabla\\lambda_0 + \\lambda_1\\nabla\\lambda_0\\times\\nabla\\lambda_2)\\\\\n",
    "\\end{align}\n",
    "$$\n",
    "\n",
    "对偶基为：\n",
    "\n",
    "$$\n",
    "\\begin{align}\n",
    "\\Phi_0(\\mathbf u) = \\int_{f_0} \\mathbf u\\cdot\\mathbf n_0\\, \\mathrm d s\\\\\n",
    "\\Phi_1(\\mathbf u) = \\int_{f_1} \\mathbf u\\cdot\\mathbf n_1\\, \\mathrm d s\\\\\n",
    "\\Phi_2(\\mathbf u) = \\int_{f_2} \\mathbf u\\cdot\\mathbf n_2\\, \\mathrm d s\\\\\n",
    "\\Phi_3(\\mathbf u) = \\int_{f_3} \\mathbf u\\cdot\\mathbf n_3\\, \\mathrm d s\\\\\n",
    "\\end{align}\n",
    "$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* $BDM_1$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$\n",
    "\\begin{align}\n",
    "\\mathbf \\phi_0 = \\lambda_1\\nabla\\lambda_2\\times\\nabla\\lambda_3 \\\\\n",
    "\\mathbf \\phi_1 = \\lambda_2\\nabla\\lambda_3\\times\\nabla\\lambda_1 \\\\\n",
    "\\mathbf \\phi_2 = \\lambda_3\\nabla\\lambda_1\\times\\nabla\\lambda_2\\\\\n",
    "\\mathbf \\phi_3 = \\lambda_0\\nabla\\lambda_3\\times\\nabla\\lambda_2 \\\\\n",
    "\\mathbf \\phi_4 = \\lambda_3\\nabla\\lambda_2\\times\\nabla\\lambda_0\\\\\n",
    "\\mathbf \\phi_5 =  \\lambda_2\\nabla\\lambda_0\\times\\nabla\\lambda_3\\\\\n",
    "\\mathbf \\phi_6 = \\lambda_0\\nabla\\lambda_1\\times\\nabla\\lambda_3\\\\\n",
    "\\mathbf \\phi_7 = \\lambda_1\\nabla\\lambda_3\\times\\nabla\\lambda_0\\\\\n",
    "\\mathbf \\phi_8 = \\lambda_3\\nabla\\lambda_0\\times\\nabla\\lambda_1\\\\\n",
    "\\mathbf \\phi_9 = \\lambda_0\\nabla\\lambda_2\\times\\nabla\\lambda_1\\\\\n",
    "\\mathbf \\phi_{10} = \\lambda_2\\nabla\\lambda_1\\times\\nabla\\lambda_0 \\\\\n",
    "\\mathbf \\phi_{11} = \\lambda_1\\nabla\\lambda_0\\times\\nabla\\lambda_2\\\\\n",
    "\\end{align}\n",
    "$$\n",
    "\n",
    "对偶基为："
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* $RT_1$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 3. 棱元"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$\n",
    "\\mathcal S_k = \\{\\mathbf p \\in [\\tilde P_k]^d : \\mathbf x\\cdot\\mathbf p = 0\\}\n",
    "$$\n",
    "\n",
    "其中 $d$ 是空间维数; $\\tilde P_k$ 为 $k$ 次齐次多项式空间。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$\n",
    "\\mathcal R_k = [P_{k-1}]^d \\oplus \\mathcal S_k\n",
    "$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "下面讨论三角形上的 Nedelec 元的构造："
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* $ d = 2, k = 1 $\n",
    "\n",
    "$$\n",
    "\\mathbf p = \n",
    "\\begin{pmatrix}\n",
    "a_1 x + a_2 y\\\\\n",
    "b_1 x + b_2 y\n",
    "\\end{pmatrix}\n",
    "$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$\n",
    "\\mathbf p\\cdot \\mathbf x = a_1 x^2 + a_2 xy +  b_1 xy + b_2 y^2 = 0\n",
    "$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$\n",
    "\\mathbf p_1 = \n",
    "\\begin{pmatrix}\n",
    "y\\\\\n",
    "-x \n",
    "\\end{pmatrix}\n",
    "$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$\n",
    "\\begin{aligned}\n",
    "&\\begin{pmatrix}\n",
    "c_1(\\lambda_0 + \\lambda_1 + \\lambda_2) + c_3 (y_0 \\lambda_0 + y_1\\lambda_1 + y_2\\lambda_2)\\\\\n",
    "c_2(\\lambda_0 + \\lambda_1 + \\lambda_2) - c_3 (x_0 \\lambda_0 + x_1\\lambda_1 + x_2\\lambda_2)\n",
    "\\end{pmatrix}\\\\\n",
    "= & \\lambda_0 \\begin{pmatrix}\n",
    "c_1 + c_3y_0 \\\\ c_2 - c_3x_0\n",
    "\\end{pmatrix} + \n",
    "\\lambda_1 \\begin{pmatrix}\n",
    "c_1 + c_3y_1 \\\\ c_2 - c_3x_1\n",
    "\\end{pmatrix} + \n",
    "\\lambda_2 \\begin{pmatrix}\n",
    "c_1 + c_3y_2 \\\\ c_2 - c_3x_2\n",
    "\\end{pmatrix}\\\\\n",
    "= & (1 - \\lambda_1 - \\lambda_2)\\begin{pmatrix}\n",
    "c_1 + c_3y_0 \\\\ c_2 - c_3x_0\n",
    "\\end{pmatrix} + \n",
    "\\lambda_1 \\begin{pmatrix}\n",
    "c_1 + c_3y_1 \\\\ c_2 - c_3x_1\n",
    "\\end{pmatrix} + \n",
    "\\lambda_2 \\begin{pmatrix}\n",
    "c_1 + c_3y_2 \\\\ c_2 - c_3x_2\n",
    "\\end{pmatrix}\n",
    "\\end{aligned}\n",
    "$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$k=1$ 的基函数在三个点处的取值的线性组合的形式。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* $ d = 2, k = 2 $\n",
    "\n",
    "$$\n",
    "\\mathbf p = \n",
    "\\begin{pmatrix}\n",
    "a_1 x^2 + a_2 xy + a_3 y^2\\\\\n",
    "b_1 x^2 + b_2 xy + b_3 y^2\n",
    "\\end{pmatrix}\n",
    "$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$\n",
    "\\mathbf p\\cdot \\mathbf x = a_1 x^3 + a_2 x^2y + a_3 xy^2 + b_1 x^2y + b_2 xy^2 + b_3 y^3 = 0\n",
    "$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$\n",
    "a_1 = 0,\\, b_3 = 0, a_2 + b_1 = 0, a_3 + b_2 = 0\n",
    "$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$\n",
    "\\begin{pmatrix}\n",
    "y^2\\\\\n",
    "-xy \n",
    "\\end{pmatrix}，\n",
    "\\begin{pmatrix}\n",
    "xy\\\\\n",
    "-x^2\n",
    "\\end{pmatrix}\n",
    "$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "所以二次的 Nedelec 基函数长这个样子：\n",
    "$$\n",
    "\\begin{pmatrix}\n",
    "a_0 + b_0 x + c_0 y \\\\ a_1 + b_1 x + c_1 y\n",
    "\\end{pmatrix}\n",
    "+ (d_0 y + d_1 x)\\begin{pmatrix}\n",
    "y \\\\ -x\n",
    "\\end{pmatrix}\n",
    "$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$\n",
    "a_0 \\begin{pmatrix}\n",
    "\\lambda_0 \\\\ 0\n",
    "\\end{pmatrix} \n",
    "+ a_1 \\begin{pmatrix}\n",
    "0 \\\\ \\lambda_0 \n",
    "\\end{pmatrix}\n",
    "+ b_0 \\begin{pmatrix}\n",
    "\\lambda_1 \\\\ 0\n",
    "\\end{pmatrix} \n",
    "+ b_1 \\begin{pmatrix}\n",
    "0 \\\\ \\lambda_1 \n",
    "\\end{pmatrix}\n",
    "+ c_0 \\begin{pmatrix}\n",
    "\\lambda_2 \\\\ 0\n",
    "\\end{pmatrix} \n",
    "+ c_1 \\begin{pmatrix}\n",
    "0 \\\\ \\lambda_2 \n",
    "\\end{pmatrix}\n",
    "$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$\n",
    "(d_0 (y_0 \\lambda_0 + y_1\\lambda_1 + y_2\\lambda_2) + d_1 (x_0 \\lambda_0 + x_1\\lambda_1 + x_2\\lambda_2))\\begin{pmatrix}\n",
    "y_0 \\lambda_0 + y_1\\lambda_1 + y_2\\lambda_2 \\\\ -(x_0 \\lambda_0 + x_1\\lambda_1 + x_2\\lambda_2)\n",
    "\\end{pmatrix}\n",
    "$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$\n",
    "\\left[\\lambda_0(d_0 y_0 + d_1 x_0) + \\lambda_1(d_0 y_1 + d_1 x_1) + \\lambda_2(d_0 y_2 + d_1 x_2) \\right]\\\\\n",
    "\\lambda_0 (y_0, -x_0) + \\lambda_1 (y_1, -x_1) + \\lambda_2 (y_2, -x_2)\n",
    "$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "*  $ d = 2, k = 3 $\n",
    "$$\n",
    "\\mathbf p = \n",
    "\\begin{pmatrix}\n",
    "a_1 x^3 + a_2 x^2y + a_3 xy^2 + a_4 y^3\\\\\n",
    "b_1 x^3 + b_2 x^2y + b_3 xy^2 + b_4 y^3\n",
    "\\end{pmatrix}\n",
    "$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$\n",
    "\\mathbf p\\cdot \\mathbf x = a_1 x^4 + a_2 x^3y + a_3 x^2y^2 + a_4 x y^3 + b_1 x^3y + b_2 x^2y^2 + b_3 xy^3 + b_4 y^4 = 0\n",
    "$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$ \n",
    "\\begin{pmatrix}\n",
    "x^2y\\\\\n",
    "-x^3 \n",
    "\\end{pmatrix}，\n",
    "\\begin{pmatrix}\n",
    "xy^2\\\\\n",
    "-x^2y\n",
    "\\end{pmatrix}，\n",
    "\\begin{pmatrix}\n",
    "y^3\\\\\n",
    "-xy^2\n",
    "\\end{pmatrix}\n",
    "$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "3 次的 Nedelec 元基函数长下面的样子：\n",
    "$$\n",
    "\\begin{pmatrix}\n",
    "a_0 + b_0 x + c_0 y + d_0 x^2 + e_0 xy + f_0 y^2 \\\\\n",
    "a_1 + b_1 x + c_1 y + d_1 x^2 + e_1 xy + f_1 y^2\n",
    "\\end{pmatrix}\n",
    "+ g_0 \\begin{pmatrix}\n",
    "x^2y\\\\\n",
    "-x^3 \n",
    "\\end{pmatrix}\n",
    "+ g_1 \\begin{pmatrix}\n",
    "xy^2\\\\\n",
    "-x^2y\n",
    "\\end{pmatrix}\n",
    "+g_2\\begin{pmatrix}\n",
    "y^3\\\\\n",
    "-xy^2\n",
    "\\end{pmatrix}\n",
    "$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "下面讨论实际坐标与重心坐标之间的关系：\n",
    "\n",
    "$$\n",
    "\\lambda_0 = a_0 + b_0 x + c_0 y\\\\\n",
    "\\lambda_1 = a_1 + b_1 x + c_1 y\\\\\n",
    "\\lambda_2 = a_2 + b_2 x + c_2 y\\\\\n",
    "$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$\n",
    "\\nabla \\lambda_0 = (b_0, c_0)^T\\\\\n",
    "\\nabla \\lambda_1 = (b_1, c_1)^T\\\\\n",
    "\\nabla \\lambda_2 = (b_2, c_2)^T\n",
    "$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "目标是基于重心坐标构造一 Nedelec 的基础函数， 就利用 $\\lambda_0$, $\\lambda_1$, 和 $\\lambda_2$ 及它们的梯度来构造。 如最低次的 Nedelec 元：\n",
    "\n",
    "$$\n",
    "\\mathbf \\phi_0 = \\lambda_1 \\nabla \\lambda_2 - \\lambda_2 \\nabla \\lambda_1 = (a_1 + b_1 x + c_1 y)(b_2, c_2) - (a_2 + b_2 x + c_2 y)(b_1, c_1) = (d_1 + d_2y, d_3 - d_2 x)\\\\\n",
    "\\mathbf \\phi_1 = \\lambda_2 \\nabla \\lambda_0 - \\lambda_0 \\nabla \\lambda_2\\\\\n",
    "\\mathbf \\phi_2 = \\lambda_0 \\nabla \\lambda_1 - \\lambda_1 \\nabla \\lambda_0\n",
    "$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "下面讨论四面体单元上的 Nedelec 元：\n",
    "\n",
    "* $ d = 3, k = 1$\n",
    "\n",
    "$$\n",
    "\\mathbf p = \n",
    "\\begin{pmatrix}\n",
    "a_1 x + a_2 y + a_3 z\\\\\n",
    "b_1 x + b_2 y + b_3 z\\\\\n",
    "c_1 x + c_2 y + c_3 z\n",
    "\\end{pmatrix}\n",
    "$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$\n",
    "\\mathbf p\\cdot \\mathbf x = x(a_1 x + a_2 y + a_3 z) + y(b_1 x + b_2 y + b_3 z) + z(c_1 x + c_2 y + c_3 z) = 0\n",
    "$$\n",
    "\n",
    "$$\n",
    "\\mathbf p\\cdot \\mathbf x = a_1 x^2 + a_2 xy + a_3 xz + b_1 xy + b_2 y^2 + b_3 yz + c_1 zx + c_2 yz + c_3 z^2 = 0\n",
    "$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$\n",
    "\\begin{aligned}\n",
    "a_1 = 0, b_2 = 0, c_3 = 0\\\\\n",
    "a_2 + b_1 = 0 \\\\\n",
    "a_3 + c_1 = 0 \\\\\n",
    "b_3 + c_2 = 0 \n",
    "\\end{aligned}\n",
    "$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$ \n",
    "\\begin{pmatrix}\n",
    "y\\\\\n",
    "-x\\\\\n",
    "0\n",
    "\\end{pmatrix},\n",
    "\\begin{pmatrix}\n",
    "z\\\\ 0 \\\\ -x\n",
    "\\end{pmatrix},\n",
    "\\begin{pmatrix}\n",
    "0 \\\\ z \\\\-y\n",
    "\\end{pmatrix}\n",
    "$$\n",
    "\n",
    "$$\n",
    "\\mathbf b \\wedge \\mathbf x = \n",
    "\\begin{pmatrix}\n",
    "b_2 z - b_3 x\\\\ b_3 x - b_1 z \\\\ b_1 y - b_2 x\n",
    "\\end{pmatrix}\n",
    "$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* $d=3, k=2$\n",
    "\n",
    "$$\n",
    "\\mathbf p = \n",
    "\\begin{pmatrix}\n",
    "a_1 x^2 + a_2 y^2 + a_3 z^2 + a_4 xy + a_5 zx + a_6 yz\\\\\n",
    "b_1 x^2 + b_2 y^2 + b_3 z^2 + b_4 xy + b_5 zx + b_6 yz\\\\\n",
    "c_1 x^2 + c_2 y^2 + c_3 z^2 + c_4 xy + c_5 zx + c_6 yz\n",
    "\\end{pmatrix}\n",
    "$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$\n",
    "\\begin{matrix}\n",
    "a_1 x^3 + a_2 xy^2 + a_3 xz^2 + a_4 x^2y + a_5 x^2z + a_6 xyz + \\\\\n",
    "b_1 x^2y + b_2 y^3 + b_3 yz^2 + b_4 xy^2 + b_5 xyz + b_6 y^2z + \\\\\n",
    "c_1 x^2z + c_2 y^2z + c_3 z^3 + c_4 xyz + c_5 xz^2 + c_6 yz^2\n",
    "\\end{matrix}\n",
    "$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$\n",
    "\\begin{aligned}\n",
    "a_1 = b_2 = c_3 = 0, \\\\\n",
    "a_2 + b_4 = a_3 + c_5 = a_4 + b_1 = a_5 + c_1 = 0\\\\\n",
    "b_3 + c_6 = b_6 + c_2 = 0 \\\\\n",
    "a_6 + b_5 + c_4 = 0\n",
    "\\end{aligned}\n",
    "$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$ \n",
    "\\begin{pmatrix}\n",
    "y^2\\\\ -xy \\\\ 0\n",
    "\\end{pmatrix}, \n",
    "\\begin{pmatrix}\n",
    "0\\\\ -yz \\\\ y^2\n",
    "\\end{pmatrix},\n",
    "\\begin{pmatrix}\n",
    "-xy\\\\x^2\\\\0\n",
    "\\end{pmatrix},\n",
    "\\begin{pmatrix}\n",
    "xz\\\\ 0 \\\\ x^2\n",
    "\\end{pmatrix},\n",
    "\\begin{pmatrix}\n",
    "z^2\\\\ 0 \\\\ -xz\n",
    "\\end{pmatrix},\n",
    "\\begin{pmatrix}\n",
    "0\\\\ -z^2\\\\ -yz\n",
    "\\end{pmatrix},\n",
    "\\begin{pmatrix}\n",
    "yz\\\\ -xz\\\\ 0\n",
    "\\end{pmatrix},\n",
    "\\begin{pmatrix}\n",
    "0\\\\ xz\\\\ -xy\n",
    "\\end{pmatrix},\n",
    "$$\n",
    "\n",
    "$$\n",
    "\\begin{pmatrix}\n",
    "yz\\\\ 0\\\\ -xy\n",
    "\\end{pmatrix}\n",
    "= \\begin{pmatrix}\n",
    "0\\\\ xz\\\\ -xy\n",
    "\\end{pmatrix} + \\begin{pmatrix}\n",
    "yz\\\\ -xz\\\\ 0\n",
    "\\end{pmatrix}\n",
    "$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 3.1 三角形单元"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* 第一类 1 次棱元："
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "基函数为： \n",
    "\n",
    "$$\n",
    "\\mathbf \\phi_0 = \\lambda_1 \\nabla \\lambda_2 - \\lambda_2 \\nabla \\lambda_1 = (a_1 + b_1 x + c_1 y)(b_2, c_2) - (a_2 + b_2 x + c_2 y)(b_1, c_1) = (d_1 + d_2y, d_3 - d_2 x)\\\\\n",
    "\\mathbf \\phi_1 = \\lambda_2 \\nabla \\lambda_0 - \\lambda_0 \\nabla \\lambda_2\\\\\n",
    "\\mathbf \\phi_2 = \\lambda_0 \\nabla \\lambda_1 - \\lambda_1 \\nabla \\lambda_0\n",
    "$$\n",
    "对偶基为：\n",
    "\n",
    "$$\n",
    "\\Phi_0(\\mathbf u) = \\int_{e_0}\\mathbf u\\cdot \\mathbf \\tau_0 \\mathrm d s\\\\\n",
    "\\Phi_1(\\mathbf u) = \\int_{e_1}\\mathbf u\\cdot \\mathbf \\tau_1 \\mathrm d s\\\\\n",
    "\\Phi_2(\\mathbf u) = \\int_{e_2}\\mathbf u\\cdot \\mathbf \\tau_2 \\mathrm d s\\\\\n",
    "$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* 第二类 1 次棱元："
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "在第一类的基础上增加：\n",
    "\n",
    "$$\n",
    "\\mathbf \\psi_0 = \\lambda_1 \\nabla \\lambda_2 + \\lambda_2 \\nabla \\lambda_1\\\\\n",
    "\\mathbf \\psi_1 = \\lambda_2 \\nabla \\lambda_0 + \\lambda_0 \\nabla \\lambda_2\\\\\n",
    "\\mathbf \\psi_2 = \\lambda_0 \\nabla \\lambda_1 + \\lambda_1 \\nabla \\lambda_0\n",
    "$$\n",
    "\n",
    "对偶基为：\n",
    "\n",
    "$$\n",
    "\\begin{align}\n",
    "\\Psi_0(\\mathbf u) =& 3\\int_{e_0}\\mathbf u\\cdot \\mathbf \\tau_0(\\lambda_1 - \\lambda_2) \\mathrm d s\\\\\n",
    "\\Psi_1(\\mathbf u) =& 3\\int_{e_1}\\mathbf u\\cdot \\mathbf \\tau_1(\\lambda_2 - \\lambda_0) \\mathrm d s\\\\\n",
    "\\Psi_2(\\mathbf u) =& 3\\int_{e_2}\\mathbf u\\cdot \\mathbf \\tau_2(\\lambda_0 - \\lambda_1) \\mathrm d s\\\\\n",
    "\\end{align}\n",
    "$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "### 3. 2 四面体单元"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* 第一类 1 次棱元："
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$\n",
    "\\begin{align}\n",
    "\\mathbf \\phi _0 = \\lambda_0\\nabla \\lambda_1 - \\lambda_1 \\nabla \\lambda_0 \\\\\n",
    "\\mathbf \\phi _1 = \\lambda_0\\nabla \\lambda_2 - \\lambda_2 \\nabla \\lambda_0 \\\\\n",
    "\\mathbf \\phi _2 = \\lambda_0\\nabla \\lambda_3 - \\lambda_3 \\nabla \\lambda_0 \\\\\n",
    "\\mathbf \\phi _3 = \\lambda_1\\nabla \\lambda_2 - \\lambda_2 \\nabla \\lambda_1 \\\\\n",
    "\\mathbf \\phi _4 = \\lambda_1\\nabla \\lambda_3 - \\lambda_3 \\nabla \\lambda_1 \\\\\n",
    "\\mathbf \\phi _5 = \\lambda_2\\nabla \\lambda_3 - \\lambda_3 \\nabla \\lambda_2 \\\\\n",
    "\\end{align}\n",
    "$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* 第二类 1 次棱元："
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "在第一类 1 次棱元的基础上， 加下面一组基："
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$\n",
    "\\begin{align}\n",
    "\\mathbf \\psi _0 = \\lambda_0\\nabla \\lambda_1 + \\lambda_1 \\nabla \\lambda_0 \\\\\n",
    "\\mathbf \\psi _1 = \\lambda_0\\nabla \\lambda_2 + \\lambda_2 \\nabla \\lambda_0 \\\\\n",
    "\\mathbf \\psi _2 = \\lambda_0\\nabla \\lambda_3 + \\lambda_3 \\nabla \\lambda_0 \\\\\n",
    "\\mathbf \\psi _3 = \\lambda_1\\nabla \\lambda_2 + \\lambda_2 \\nabla \\lambda_1 \\\\\n",
    "\\mathbf \\psi _4 = \\lambda_1\\nabla \\lambda_3 + \\lambda_3 \\nabla \\lambda_1 \\\\\n",
    "\\mathbf \\psi _5 = \\lambda_2\\nabla \\lambda_3 + \\lambda_3 \\nabla \\lambda_2 \\\\\n",
    "\\end{align}\n",
    "$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "from sympy import * # 导入 sympy 中的所有功能\n",
    "init_printing(use_latex=True) \n",
    "from IPython.display import display # 显示公式"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "x0, y0, x1, y1, x2, y2, x, y = symbols('x_0, y_0, x_1, y_1, x_2, y_2, x, y')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'lambda_0:='"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXMAAAAtBAMAAACuZ5aSAAAAMFBMVEX///8AAAAAAAAAAAAAAAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAEHarIkSJZt3NVLsy\nme8Q6PJIAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAFSklEQVRoBe2YTWhcZRSG30kzyThJm0sKgqve\nRsguNhQRu5uNCIIaunAlJBa3wex0UwhFsV2ZZaMuKriQCjHapYiz7UJSdaGhgrE73ZhUiyDC9Pzd\n7+/+gYugZb7FzL3nPOf93vl6Z9q+wHglJ9DPk0J62wqkA8d23+qsFTg2q+lGrc5agVSx6X7+yecW\n885SjpeyEtZZePriJcx/h8lfSj3IoJQ9UDjTQW4myq2AzMi2FdNc8quzNn2ltzXVP8A5zG75ulw9\njrfya1jbwcTh1N1v46YOyowA0i2c6SBuA6q8/pWdSwywqAKRtk77ZsmX0lPZ1FF/8MLJLXw5+/1m\npAC8hjeyjydv7GNm93VciJs6yDMKSLdwJoP45llAlKcGJ+xUYoBFBYilddo1y74U7+CxXSA7leM+\n+ptc61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bW\nA8BSwV7uFPkiyBwFEC0hzHoK0AHn0i8yMgOkzMGjV1Cs2MIBal0TQzqpexYpptYDwFLBdRO0tyBz\nFEC0pGfWUwBp8GiAlDl49ArxFg5Q65oY0vP5wBLD1HoAaCroYkPTDTJHAUQrtJ4CcAr22QyQMgeP\nXiHewgFqXZv2q8CJYWo9AqLY0HTtrb8pF/swLbpzz7p0HFAXPFoeGSrIoHtxQGh94g79FmtiuOPI\n8EKAJDYM++TzwHJFQaUX54oOqAkepSxbeIVoCw9Eoej6eqaRIseDVYuBpthQ8kCNDRktLw/UBI9S\nblLwQCl8bEoMxUpr8HeswEPWuRPP/02HFAAAAABJRU5ErkJggg==\n",
      "text/latex": [
       "$$\\frac{x y_{1} - x y_{2} - x_{1} y + x_{1} y_{2} + x_{2} y - x_{2} y_{1}}{x_{0} y_{1} - x_{0} y_{2} - x_{1} y_{0} + x_{1} y_{2} + x_{2} y_{0} - x_{2} y_{1}}$$"
      ],
      "text/plain": [
       "  x⋅y₁ - x⋅y₂ - x₁⋅y + x₁⋅y₂ + x₂⋅y - x₂⋅y₁  \n",
       "─────────────────────────────────────────────\n",
       "x₀⋅y₁ - x₀⋅y₂ - x₁⋅y₀ + x₁⋅y₂ + x₂⋅y₀ - x₂⋅y₁"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "'lmabda_1:='"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXMAAAAtBAMAAACuZ5aSAAAAMFBMVEX///8AAAAAAAAAAAAAAAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAEM3dMnarIkSJZlS7\nme8N5bApAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAFPUlEQVRoBe1YTYhbVRj9YpImmUxn3mYqrhpS\ncKMLqRRLFxq6l3ldjDCL2KFSxF2WoqhZ2IWri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GFReGI/3EjiLyugEShNLfUlPc+XbRLOWLvV7xSAhZYRSZWouJZSC1D1bsx04pDsw/r+u\n5FvqkH5Js8ea7cBsB2Y78B/ZgfC/3AlTUwmJnoMpTXU2lXAwPhNTpjqbSkiIeqWytJBpjlAQGRYS\njLN/TjA+kwoTaeFZQ9erR0hHhkqodTAoaKfSygmCDR312ZRA5Ugh9OAINExjRpcWPv2c0s3FxYkF\nkaEQat8/BkJwqaA6iwkudAwIXI7yTjUhCo7AwybTwg+Z7hJBFydqGBlHhkKANlpPp5UTBFFwuaKO\noLKvMOHBEngY+ozSQrFu9pyullAUGRJB1ArSypDgQkfzY+ARUg4VrA1ScARjPUoLJ61bQlFkSARR\nK0grQ4ILHa11JnAWGSpY6yFBhk2khbF1j5CODDWopAOTTitjggsd1boSOIu8FuSdaj0m6FfMMaOX\nFsbWvTgxHRlqUMnWk2llTHCho1pXAmeRoYJajwlifSItjK17hHRkqEElW0+mlTHBhY5qXQmcRYYK\naj0miHUBvbQwth4QSiJDtk6ZYlFaaQkudLRnnYdoFukrqHW9WIJv3UsLr4Z0/cSE0sgQ/zWSTLEo\nrbQEFzoGuSKXy3JFRwDSMsumha88ddHUgisRyiLDxje/56WpoCMUhI5cLssVHYG1fHtlaSHzpoZ+\nB0r4G7QlNw2AzKSpAAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$$\\frac{- x y_{0} + x y_{2} + x_{0} y - x_{0} y_{2} - x_{2} y + x_{2} y_{0}}{x_{0} y_{1} - x_{0} y_{2} - x_{1} y_{0} + x_{1} y_{2} + x_{2} y_{0} - x_{2} y_{1}}$$"
      ],
      "text/plain": [
       "  -x⋅y₀ + x⋅y₂ + x₀⋅y - x₀⋅y₂ - x₂⋅y + x₂⋅y₀ \n",
       "─────────────────────────────────────────────\n",
       "x₀⋅y₁ - x₀⋅y₂ - x₁⋅y₀ + x₁⋅y₂ + x₂⋅y₀ - x₂⋅y₁"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "'lmabda_2:='"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXMAAAAtBAMAAACuZ5aSAAAAMFBMVEX///8AAAAAAAAAAAAAAAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAEHarIkSJZt3NVLsy\nme8Q6PJIAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAFEUlEQVRoBe2YT2hcVRTGv5lOJuNkmgwpCK76\nGiG7saWI6G42IghK6MKVkJh9cFbqMhSk7cosG9tFRBfiokRdiphtF5KqoAYFY3e6SmqLIIF4z593\n3z33vnkPuhi0zF103jvnd777zc2bofMB0xWdQDeLCvFtLRAPTOy+1lktMDGr8Ua1zmqBWLHqfvHZ\nl5ezxiDD6/0Eayw9f2Udi9+j9XvSAw9yuQByZzJIzUi5FuAZ3rZkmkrFaqzNXu1stbuHuIjl5aLO\nV0/jvewG1u6geYS7UU8GeUYA6ufOZLC5vgZR7m3ptAVIVAAjLtNFM/EldLvfPu4OXz27ha9m17qX\njATewtv9T1o7B5jb/fZF24IM0owA3M6d8SDewcdg5d4PmzptARJlwGrLtG+mvgRv4KldoD+f4UFn\nBceu2Lh53a0be+6yj1vuHvexkOFT5p+h3vXbhPEgzSiA9vb2zT+2t+nt8yDex0KfldHdpOkEIFEB\n0m3hm+qLFKLlbAGr/d7J+T38GfXwwBVmjrG/p9bDPg3yjADUyg8VNNg4wfwOK6v1GGB3AtBwsGhb\n3nGcL2GdLeAAzcP9Ia5Jyf/bO3GX7mF6ToR8nS9okGcEoJq3ToO9h+iMWLnEOiuzO9qaZoNlmyW+\nmO32L6LZx5eYu7Tfx9Vg3l1+5D6eF1zHtZNTl0GeEYBGc+s82DtGJ2Pl1LoosyhtXbatb6a+BF/d\n+QavAL9gdeTe3X2jMfPP3FFrhLO7M3+n1mWQZwSgUbUug+7U3UeIlBPrqsz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y_{1} - x_{0} y_{2} - x_{1} y_{0} + x_{1} y_{2} + x_{2} y_{0} - x_{2} y_{1}}$$"
      ],
      "text/plain": [
       "  x⋅y₀ - x⋅y₁ - x₀⋅y + x₀⋅y₁ + x₁⋅y - x₁⋅y₀  \n",
       "─────────────────────────────────────────────\n",
       "x₀⋅y₁ - x₀⋅y₂ - x₁⋅y₀ + x₁⋅y₂ + x₂⋅y₀ - x₂⋅y₁"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "A = Matrix([[x0, x1, x2], [y0, y1, y2], [1, 1, 1]])\n",
    "A0 = Matrix([[x, x1, x2], [y, y1, y2], [1, 1, 1]])\n",
    "A1 = Matrix([[x0, x, x2], [y0, y, y2], [1, 1, 1]])\n",
    "A2 = Matrix([[x0, x1, x], [y0, y1, y], [1, 1, 1]])\n",
    "a0 = A0.det()/A.det()\n",
    "a1 = A1.det()/A.det()\n",
    "a2 = A2.det()/A.det()\n",
    "display('lambda_0:=', a0)\n",
    "display('lmabda_1:=', a1)\n",
    "display('lmabda_2:=', a2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAAgAAAAPBAMAAAArJJMAAAAAHlBMVEX///8AAAAAAAAAAAAAAAAA\nAAAAAAAAAAAAAAAAAACGjDitAAAACXRSTlMAVO8Qq5l2zWYZcMvdAAAACXBIWXMAAA7EAAAOxAGV\nKw4bAAAAHUlEQVQIHWNgAANGZQYGk5DJQDYbqQSr03QPsBkAJYgIYEZbtZEAAAAASUVORK5CYII=\n",
      "text/latex": [
       "$$1$$"
      ],
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = a0 + a1 + a2\n",
    "a.simplify()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.2"
  },
  "latex_envs": {
   "bibliofile": "biblio.bib",
   "cite_by": "apalike",
   "current_citInitial": 1,
   "eqLabelWithNumbers": true,
   "eqNumInitial": 0
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
